home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / glass / glass.lha / GLASS / glue / stackprocs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-31  |  1.6 KB  |  66 lines

  1.  
  2. /*
  3.  
  4.     This file is a part of the GLASS source distribution 
  5.     and therefore subjected to the copy notice below. 
  6.     
  7.     Copyright (C) 1989,1990  S.J. Klaver, R Doesborg
  8.               email: simon@sagan.nl
  9.  
  10.     This program is free software; you can redistribute it and/or modify
  11.     it under the terms of the GNU General Public License as published by
  12.     the Free Software Foundation version 1
  13.  
  14.     This program is distributed in the hope that it will be useful,
  15.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.     GNU General Public License for more details.
  18.  
  19.     You should have received a copy of the GNU General Public License
  20.     along with this program; if not, write to the Free Software
  21.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */
  23. #include <stdio.h>
  24.  
  25. typedef struct stackel
  26.   { int menuid;
  27.     int itemindex;
  28.   };
  29.  
  30. #define STACKSIZE 10
  31.  
  32. static struct stackel stack[STACKSIZE];
  33. static int stackpointer = 0;
  34.  
  35. int push_element (id, index)
  36.   int id;
  37.   int index;
  38. {
  39.   if (stackpointer == STACKSIZE) {
  40.     fprintf(stderr, "Stack overflow ...\n");
  41.     return(1);
  42.   }
  43.   else {
  44.     stackpointer++;
  45.     stack[stackpointer].menuid = id;
  46.     stack[stackpointer].itemindex = index;
  47.     return(0);
  48.   }
  49. }
  50.  
  51. int pull_element (id, index)
  52.   int *id;
  53.   int *index;
  54. {
  55.   if (stackpointer == 0) {
  56.     fprintf(stderr, "Illegal pull: stack empty.\n");
  57.     return(1);
  58.   }
  59.   else {
  60.     *id = stack[stackpointer].menuid;
  61.     *index = stack[stackpointer].itemindex;
  62.     stackpointer--;
  63.     return(0);
  64.   }
  65. }
  66.